package demo2;

import demo1.Goods;

import java.util.ArrayList;
import java.util.StringJoiner;

public class ArrayUtil {
    private ArrayUtil() {}
    public static String printArray(int[] arr) {
        StringJoiner sj = new StringJoiner(",","[","]");
        for (int i = 0; i < arr.length; i++) {
            sj.add(String.valueOf(arr[i]));
        }
                return sj.toString();
    }
    public static double getAverage(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum / arr.length;
    }

    public static double getMax(ArrayList<Goods> list) {
        double max = 0;
        for (int i = 0; i < list.size(); i++) {
            double temp = list.get(i).getPrice();
            if (max < temp) {
                max = temp;
            }
        }
        return max;
    }
}
